|
|
|
|
|
|
|
to change the flow of execution, your application would not be very flexible and would also not work very well. The creation of your application is really the process of logically handling the data that the user will input. |
|
|
|
|
|
|
|
|
Unfortunately, in programming there is no one way to do something. This still holds true even in Visual Basic. Your application will process the data that it is given by testing and comparing the data, then execute different sections of code based on the results. This process is commonly referred to as condition execution of the code. |
|
|
|
|
|
|
|
|
To conditionally execute any code in your application, you must first be able to test it. This test is called a condition. If the condition is True, then the related code will be executed; if the condition is False, then the related code will be skipped. The way most programming languages, including Visual Basic, perform this testing is with one of two types of statement groups. The first and oldest of the two is the If-Then-End If statement block. The second and sexier of the two is the Select Case statement group. Both of these statement groups use the expressions that you can create using operators, variables, and functions. |
|
|
|
|
|
|
|
|
You might think that you know the If-Then statement like the back of your hand, but you probably are not aware of a few ways to use it. In addition, several variations of the If-Then statement help when developing the application for multiple operating systems. A typical If-Then statement in an application tests a particular input data value and, if it isn't in the database, processes it accordingly. The following code uses several of the concepts that you have already seen during this first week: |
|
|
|
|
|
|
|
|
If (keyascii < 48 Or keyascii > 58) And keyascii <> 8 Then
Beep
keyascii = 0
End If |
|
|
|
|
|
|
|
|
This simple, boring way to use the If-Then statement only enables you to conditionally execute a single section of code. However, if you want to execute one section if the condition is true and another if it is false, you would use the Else clause of the If-Then statement. The code would then resemble the following: |
|
|
|
|
|
|
|
|
If IsDate (entdate.Text) Then
entdate.Text = DateAdd (d, 1, entdate.Text)
Else
Beep
End If |
|
|
|
|
|